package com.example.auth.repository;

import com.example.auth.entity.Task;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface TaskRepository extends JpaRepository<Task, Long> {

    List<Task> findBySupervisorId(Long supervisorId);

    List<Task> findByAssigneeId(Long assigneeId);

    List<Task> findBySupervisorIdAndStatus(Long supervisorId, String status);
    

    List<Task> findByAssigneeIdAndStatus(Long assigneeId, String status);

    List<Task> findByProjectId(Long projectId);

    List<Task> findByProjectIdAndCompleted(Long projectId, Boolean completed);

    long countByProjectIdAndCompleted(Long projectId, Boolean completed);

    @Query("SELECT COUNT(t) = 0 FROM Task t WHERE t.projectId = ?1 AND t.completed = false")
    boolean areAllTasksCompletedForProject(Long projectId);

    List<Task> findBySupervisorIdAndProjectIdIsNull(Long supervisorId);

    List<Task> findBySupervisorIdAndStatusAndProjectIdIsNull(Long supervisorId, String status);
} 